#ifndef FHE_CORE_SERIALIZER_H
#define FHE_CORE_SERIALIZER_H

#include <fhe/core/ISerializer.h>

namespace fhe
{
  namespace core
  {
    template <typename T>
    class Serializer : public ISerializer
    {
    public:
      typedef void (*Serialize)( const Data::Ptr& data, T t );
      typedef T (*Deserialize)( const Data::Ptr& data );
      
      Serializer( const std::string& name, Serialize serialize, Deserialize deserialize )
        : name_( name )
        , serialize_( serialize )
        , deserialize_( deserialize )
      {
      }
      
      std::string name() const
      {
        return name_;
      }
      
      const std::type_info& type() const
      {
        return typeid(T);
      }
      
      void serialize( const Data::Ptr& data, const Val& val ) const
      {
        FHE_ASSERT( val.is<T>() );
        return (*serialize_)( data, val.get<T>() );
      }
      
      Val deserialize( const Data::Ptr& data ) const
      {
        return (*deserialize_)( data );
      }
      
    private:
      std::string name_;
      Serialize serialize_;
      Deserialize deserialize_;
    };
  }
}

#endif
